<?php

class Auto_Db_Simple extends Zend_Db_Table_Abstract
{
    public function getList()
    {
        return $this->fetchAll();
    }

    public function getOptions()
    {
        $items = $this->getList();

        $out = array();
        foreach ($items as $item) {
            $out[$item->id] = $item->name;
        }

        return $out;
    }

    public function create($name)
    {
        if (empty($name)) {
            throw new Zend_Db_Exception('Невалидно име');
        }
        $this->insert(array('name' => $name));
    }

    public function edit($id, $name)
    {
        if (empty($name)) {
            throw new Zend_Db_Exception('Невалидно име');
        }
        $this->update(
            array('name' => $name),
            $this->getAdapter()->quoteInto('id=?', $id)
        );
    }

    public function remove($id)
    {
        $this->delete($this->getAdapter()->quoteInto('id=?', $id));
    }
}
